package com.example.controller;

import com.example.pojo.Address;
import com.example.pojo.Result;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
public class ResponseController {
//    @RequestMapping("/hello")
//    public String hello(){
//        System.out.println("hello world!");
//        return "hello world!"; //
//    }
//
//    @RequestMapping("/getAddr")
//    public Address getAddr(){
//        Address addr = new Address();
//        addr.setCity("深圳");
//        addr.setProvince("广东");
//        return addr;// { "province": "广东","city": "深圳"}
//    }
//    @RequestMapping("/listAddr")
//    public List<Address>  listAddr(){
//       List<Address> list = new ArrayList<>();
//       Address addr1 = new Address();
//       addr1.setCity("深圳");
//       addr1.setProvince("广东");
//       list.add(addr1);
//       Address addr2 = new Address();
//       addr2.setCity("广州");
//       addr2.setProvince("广东");
//       list.add(addr2);
//        return list;// [{ "province": "广东","city": "深圳"},{ "province": "广东","city": "广州"}]
//    }

    //统一返回结果格式
    @RequestMapping("/hello")
    public Result hello() {
        System.out.println("hello world!");
        return Result.success("hello world!"); //
    }

    @RequestMapping("/getAddr")
    public Result getAddr() {
        Address addr = new Address();
        addr.setCity("深圳");
        addr.setProvince("广东");
        return Result.success(addr);// { "province": "广东","city": "深圳"}
    }

    @RequestMapping("/listAddr")
    public Result listAddr() {
        List<Address> list = new ArrayList<>();
        Address addr1 = new Address();
        addr1.setCity("深圳");
        addr1.setProvince("广东");
        list.add(addr1);
        Address addr2 = new Address();
        addr2.setCity("广州");
        addr2.setProvince("广东");
        list.add(addr2);
        return Result.success(list);//{"code": 1,"msg": "success","data": [{ "province": "广东","city": "深圳"},{"province": "广东","city": "广州"}]
    }
}

